package br.com.dwii.tpg2.entidade;

import br.com.dwii.tpg2.util.DBUtil;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Diego
 */
public class Uf {
    
    private Long id;
    private String sigla;
    private String nome;
    private List<Uf> listAll;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getSigla() {
        return sigla;
    }

    public void setSigla(String sigla) {
        this.sigla = sigla;
    }
    
    public List<Uf> getListAll() throws SQLException {
        List<Uf> listObject = new ArrayList<Uf>();
        Connection conn = DBUtil.getConnection();
        Statement s = null;
        ResultSet rs = null;
        try {
            s = conn.createStatement();
            rs = s.executeQuery("select * from uf order by sigla");
            while (rs.next()) {
                Uf obj = new Uf();
                obj.setId(rs.getLong(1));
                obj.setSigla(rs.getString(2));
                obj.setNome(rs.getString(3));
                listObject.add(obj);
            }
        } catch (SQLException ex) {
            Logger.getLogger(Animal.class.getName()).log(Level.SEVERE, null, ex);
            throw ex;
        } finally {
            s.close();
            rs.close();
            conn.close();
        }
        return listObject;
    }
}
